﻿#if UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_WSA || UNITY_WEBGL
using UnityEngine;
using System.Collections.Generic;

namespace GameDesigner
{
    public class ActionAudio : ActionCoreBase
    {
        /// <summary>
        /// 音效触发模式
        /// </summary>
		public AudioMode audioModel = AudioMode.AnimEvent;
        /// <summary>
        /// 音效剪辑
        /// </summary>
		public List<AudioClip> audioClips = new();

        public override void OnEnter()
        {
            base.OnEnter();
            if (audioModel == AudioMode.EnterPlay & audioClips.Count > 0)
            {
                var audioIndex = Random.Range(0, audioClips.Count);
                AudioManager.Play(audioClips[audioIndex]);
            }
        }

        public override void OnAnimationEvent()
        {
            if (audioModel == AudioMode.AnimEvent & audioClips.Count > 0)
            {
                var audioIndex = Random.Range(0, audioClips.Count);
                AudioManager.Play(audioClips[audioIndex]);
            }
        }

        public override void OnExit()
        {
            base.OnExit();
            if (audioModel == AudioMode.ExitPlay & audioClips.Count > 0)
            {
                var audioIndex = Random.Range(0, audioClips.Count);
                AudioManager.Play(audioClips[audioIndex]);
            }
        }
    }
}
#endif